/**
 * @author zulianp@lu.unisi.ch &  lemmar@lu.unisi.ch
 */

package ch.unisi.inf.projects.java.uom.gui.commands;

import java.awt.event.ActionEvent;
import ch.unisi.inf.projects.java.uom.elements.Item;
import ch.unisi.inf.projects.java.uom.gui.itemeditor.fieldselector.EntryGUI;

public final class ReferenceChooseCommand extends Command{

	private final Item item;
	private final EntryGUI entryGUI;
	private String label;
	private static final long serialVersionUID = -1L;

	
	public ReferenceChooseCommand(final Item item,final  EntryGUI entryGUI) {
		this.item = item;
		this.entryGUI = entryGUI;
		label = item.getField("STRING_NAME");
		if(label == null)
			label = item.getName();
		
		putValue(NAME, label);
		putValue(SHORT_DESCRIPTION, "Click on " + label + '\n' + "to choose the reference of this entry");
		
	}
	public void actionPerformed(ActionEvent ev) {
		String value = item.getName();
		entryGUI.setValue(value);
		
	}
	
	public String toString()
	{
		return label;
	}

}
